﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace GroupChat2013.Main.Controls
{
    public partial class AppItem : UserControl
    {
        /// <summary>
        /// 应用图标
        /// </summary>
        public Image AppIco { get; set; }

        /// <summary>
        /// 应用名称
        /// </summary>
        public string AppName { get; set; }

        /// <summary>
        /// 应用地址
        /// </summary>
        public string AppUrl { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public AppItem()
        {
            InitializeComponent();

            Init();
            this.BackColor = Color.Transparent;

            //this.Load += new EventHandler(AppItem_Load);
            this.Click += new EventHandler(AppItem_Click);
            this.spAppIco.Click += new EventHandler(AppItem_Click);
            this.slAppName.Click += new EventHandler(AppItem_Click);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="appIco"></param>
        /// <param name="appName"></param>
        /// <param name="appUrl"></param>
        public AppItem(Image appIco, string appName, string appUrl)
            : base()
        {
            this.AppIco = appIco;
            this.AppName = AppName;
            this.AppUrl = appUrl;
        }

        private void Init()
        {
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.StandardDoubleClick, false);
            this.SetStyle(ControlStyles.Selectable, true);
            this.UpdateStyles();
        }

        #region 窗体事件

        private void AppItem_Load(object sender, EventArgs e)
        {
            spAppIco.BackgroundImage = AppIco;
            slAppName.Text = AppName;
        }

        private void AppItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("点击了" + AppName);
        }

        #endregion
    }
}
